package cloudInformation.controller;

import cloudEntity.dto.user.SmartUserRelaxDetailsDTO;
import cloudEntity.dto.user.SmartUserRelaxDetailsUpdateTypeDTO;
import cloudEntity.utils.ResultUtils;
import cloudEntity.vo.user.SmartUserRelaxDetailsVO;
import cloudInformation.annotate.AuthCheck;
import cloudInformation.mapper.SmartUserRelaxDetailsMapper;
import cloudInformation.service.SmartUserRelaxDetailsService;
import huang.cloudUserApi.AuthFeignClient;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: Smart School
 * @ClassName UserRelaxDetailsController
 * @description: 学生请假详情控制器
 * @author: 陈智博
 * @create: 2025-04-15 10:23
 * @Version 1.0
 **/
@RestController
@RequestMapping(value = "/relax")
@Tag(name = "用户请假控制器")
public class UserRelaxDetailsController {

    @Autowired
    private AuthFeignClient authFeignClient;

    // 注入 Mapper
    @Autowired
    private SmartUserRelaxDetailsMapper smartUserRelaxDetailsMapper;

    //注入 Service
    @Autowired
    private SmartUserRelaxDetailsService smartUserRelaxDetailsService;

    @Operation(summary = "获取用户请假详情列表")
    @RequestMapping(value = "/getDetails",method = RequestMethod.GET)
    public ResultUtils<List<SmartUserRelaxDetailsVO>> GetUserRelaxDetails() {
        String sysUserUid = authFeignClient.smartUser().getSysUserUid();
        return ResultUtils.success(smartUserRelaxDetailsMapper.getUserRelaxDetails(sysUserUid));
    }

    @Operation(summary = "创建请假信息")
    @Parameter(name = "smartUserRelaxDetailsDTO",description = "请假信息详情DTO",required = true)
    @RequestMapping(value = "/createRelaxDetails",method = RequestMethod.POST)
    @AuthCheck(values = "ROLE_TEACHER")
    public ResultUtils CreateUserRelaxDetails(@RequestBody SmartUserRelaxDetailsDTO smartUserRelaxDetailsDTO) {
        Integer relax = smartUserRelaxDetailsService.createRelax(smartUserRelaxDetailsDTO);
        if(relax>0)
        {
            return ResultUtils.success(relax,"请假成功");
        }
        return ResultUtils.failed("创建请假信息失败!");
    }

    @Operation(summary = "修改请假信息")
    @Parameter(name = "smartUserRelaxDetailsUpdateTypeDTO",description = "请假信息详情修改类型DTO",required = true)
    @RequestMapping(value = "/updateRelaxDetails",method = RequestMethod.POST)
    @AuthCheck(values = "ROLE_TEACHER")
    public ResultUtils UpdateRelaxDetails(@RequestBody SmartUserRelaxDetailsUpdateTypeDTO smartUserRelaxDetailsUpdateTypeDTO) {
        Integer i = smartUserRelaxDetailsMapper.updateUserRelaxDetails(smartUserRelaxDetailsUpdateTypeDTO);
        if(i>0)
        {
            return ResultUtils.success("修改成功!");
        }
        return ResultUtils.failed("修改失败");
    }

}
